/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author TQNINH
 */
public class TransferManager implements Runnable {
    static int transferCount = 0;
    CustomerAccount accSend;
    CustomerAccount accReceive;
    double amount;
    
    public TransferManager(CustomerAccount send, CustomerAccount receive, double a){
        this.accSend = send;
        this.accReceive = receive;
        this.amount = a;
    }
    
    synchronized public void run(){
        System.out.println("Before transferring:");
        
        accSend.InfoAccount();
        accReceive.InfoAccount();
        
        double sendBalance = accSend.getBalance();
        double receiveBalance = accReceive.getBalance();
        
        if(amount > 0 && amount < sendBalance){
            System.out.println("After transferring " + amount);
            sendBalance = sendBalance - amount;
            accSend.setBalance(sendBalance);
            
            receiveBalance = receiveBalance + amount;
            accReceive.setBalance(receiveBalance);
            
            transferCount++;
            
            accSend.InfoAccount();
            accReceive.InfoAccount();
            System.out.println("Number of transferring:" + transferCount);
        } else {
            System.out.println("Transfering not complete because amount not valid!!!");
        }
    }
}
